using Microsoft.Win32;

namespace PlexMediaLinker
{
    // 管理全局开机自启动
    public static class AutoStartManager
    {
        private const string RunKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
        private const string AppName = "PlexMediaLinker";

        public static void SetAutoStart(bool enable)
        {
            using var rk = Registry.CurrentUser.OpenSubKey(RunKey, true);
            var exe = Application.ExecutablePath;
            if (enable) rk.SetValue(AppName, exe);
            else rk.DeleteValue(AppName, false);
        }

        public static bool IsEnabled()
        {
            using var rk = Registry.CurrentUser.OpenSubKey(RunKey, false);
            var val = rk?.GetValue(AppName) as string;
            return string.Equals(val, Application.ExecutablePath, StringComparison.OrdinalIgnoreCase);
        }
    }
}